package com.polymathcoder.dpastry.api.pastry;

import java.io.Serializable;
import java.util.NoSuchElementException;

/**
 * Created by IntelliJ IDEA.
 * User: Drew
 * Date: Jul 5, 2010
 * Time: 12:38:11 AM
 * To change this template use File | Settings | File Templates.
 */
public interface NodeHandleSet extends Serializable {
    /**
   * Puts a NodeHandle into the set.
   *
   * @param handle the handle to put.
   *
   * @return true if the put succeeded, false otherwise.
   */
  public boolean putHandle(NodeHandle handle);

  /**
   * Finds the NodeHandle associated with the NodeId.
   *
   * @param id a node id.
   * @return the handle associated with that id or null if no such handle is found.
   */
  public NodeHandle getHandle(Id id);

  /**
   * Gets the ith element in the set.
   *
   * @param i an index.
   * @return the handle associated with that id or null if no such handle is found.
   */
  public NodeHandle getHandle(int i);

  /**
   * Verifies if the set contains this particular id.
   *
   * @param id a node id.
   * @return true if that node id is in the set, false otherwise.
   */
  public boolean memberHandle(Id id);

  /**
   * Removes a node id and its handle from the set.
   *
   * @param id the node to remove.
   *
   * @return the node handle removed or null if nothing.
   */
  public NodeHandle removeHandle(Id id);

  /**
   * Gets the size of the set.
   *
   * @return the size.
   */
  public int size();

  /**
   * Gets the index of the element with the given node id.
   *
   * @param id the id.
   *
   * @return the index or throws a NoSuchElementException.
   */
  public int getIndexHandle(Id id) throws NoSuchElementException;  

  public short getType();
}
